import DataSet, { DataSetProps } from 'choerodon-ui/pro/lib/data-set/DataSet';
import { FieldType } from 'choerodon-ui/pro/lib/data-set/enum';
import request from 'utils/request';
import { API_HOST } from 'utils/config';
import { isTenantRoleLevel, getCurrentOrganizationId } from 'utils/utils';
import { getUrlParamHref, getLovDefineAxiosConfig, getLovQueryAxiosConfig } from './utils';

export const TableListDataSetConfig = (lineBoCode): DataSetProps => {
  const pModeTypeDS = new DataSet({
    paging: false,
    data: [
      { value: 'use', meaning: '使用' },
      { value: 'cancel', meaning: '取消' },
      { value: 'deliver', meaning: '发出' },
    ]
  });
  return {
    autoQuery: false,
    autoCreate: false,
    pageSize: 10,
    paging: false,
    transport: {
      submit: ({ data }) => {
        return {
          url: `/hmde/v1${isTenantRoleLevel() ? `/${getCurrentOrganizationId()}` : ''}/executor/${lineBoCode}/batch-update`,
          method: 'POST',
          data,
        };
      },
      read: ({ params }) => {
        return {
          url: `/hmde/v1${isTenantRoleLevel() ? `/${getCurrentOrganizationId()}` : ''}/executor/${lineBoCode}/list`,
          method: 'GET',
          params: {
            ...params,
          },
        };
      },
      destroy: ({ data }) => {
        return {
          url: `/hmde/v1${isTenantRoleLevel() ? `/${getCurrentOrganizationId()}` : ''}/executor/${lineBoCode}/batch-delete`,
          method: 'DELETE',
          data,
        };
      },
    },
    fields: [
      {
        name: 'processMode',
        type: FieldType.string,
        label: '处理模式',
        options: pModeTypeDS,
      },
      {
        name: 'processDate',
        type: FieldType.date,
        label: '处理日期',
      },
      {
        name: 'processPercent',
        type: FieldType.number,
        label: '处理比率',
      },
      {
        name: 'processQuantity',
        type: FieldType.number,
        label: '处理数量',
      },
      {
        name: 'remark',
        type: FieldType.number,
        label: '处理说明',
      },
    ],
    queryFields: [
      {
        name: 'processMode',
        type: FieldType.string,
        label: '处理模式',
        options: pModeTypeDS,
      },
      {
        name: 'processDate',
        type: FieldType.date,
        label: '处理日期',
      },
      {
        name: 'processPercent',
        type: FieldType.number,
        label: '处理比率',
      },
      {
        name: 'processQuantity',
        type: FieldType.number,
        label: '处理数量',
      },
      {
        name: 'remark',
        type: FieldType.number,
        label: '处理说明',
      },
    ],
    events: {
      update: ({ name, record }) => {
        console.log('update');
      }
    }
  };
};

export const saveAll = ({ header, body, headerBoCode }) => {
  return request(
    `${API_HOST}/hmde/v1${isTenantRoleLevel() ? `/${getCurrentOrganizationId()}` : ''}/executor/${headerBoCode}/batch-update`,
    {
      method: 'POST',
      data: body,
      headers: {
        ...header,
      },
    },
  );
};
